package me.king.mybatis.component.page;

import java.util.List;

import me.king.mybatis.component.biz.IBaseService;
import me.king.mybatis.component.biz.TransactionSupportService;

@SuppressWarnings({"rawtypes","unchecked"})
public class PageBean<T> extends TransactionSupportService {
	
	public PageBean(PageInParam pip) {
		this.pip = pip;
	}
	
	private IBaseService ibaseService = getBaseServiceTemplate();
	private int count;
	private List<T> data;
	private int prev;
	private int next;
	private PageInParam pip;
	
	public PageBean<T> getBean(Class cls) {
		count = (int) ibaseService.selectSingle(cls, "findCountPage", pip);
		prev = pip.getCurr() - 1 < 1 ? 1:pip.getCurr() - 1;
		next = pip.getCurr() + 1 > count ? count:pip.getCurr() + 1;
		data = ibaseService.select(cls, "findCurrPageData", pip);
		return this;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public int getPrev() {
		return prev;
	}

	public IBaseService<T> getIbaseService() {
		return ibaseService;
	}

	public void setIbaseService(IBaseService<T> ibaseService) {
		this.ibaseService = ibaseService;
	}

	public void setPrev(int prev) {
		this.prev = prev;
	}

	public int getNext() {
		return next;
	}

	public void setNext(int next) {
		this.next = next;
	}

	public PageInParam getPip() {
		return pip;
	}

	public void setPip(PageInParam pip) {
		this.pip = pip;
	}	
	
}
